|
RAIS
3.2
|
00001 00027 using System; 00028 using System.Collections.Generic; 00029 using System.Text; 00030 00031 using System.Web.UI; 00032 using System.Web.UI.WebControls; 00033 00034 namespace RAIS.UI.Common 00035 { 00039 class Controls 00040 { 00041 #region Public static methods 00042 00047 public static void InitializeList(ListItemCollection items, string[] itemNames) 00048 { 00049 // Items are not in the same order as they was selected from DB 00050 // after AddMissingItems and RemoveUnmatchedItems using (because 00051 // AddMissingItems adds items to the end of the list) 00052 // that's why clear the list and fill it in again 00053 //AddMissingItems(items, itemNames); 00054 //RemoveUnmatchedItems(items, itemNames); 00055 items.Clear(); 00056 if (itemNames != null) 00057 { 00058 foreach (string itemName in itemNames) 00059 { 00060 ListItem item = new ListItem(itemName); 00061 items.Add(item); 00062 } 00063 } 00064 00065 UI.Common.PageManagement.InitializeItemsTooltips(items); 00066 } 00067 00068 public static void InitializeList(ListItemCollection items, string[] itemNames, string[] itemValues) 00069 { 00070 // Items are not in the same order as they was selected from DB 00071 // after AddMissingItems and RemoveUnmatchedItems using (because 00072 // AddMissingItems adds items to the end of the list) 00073 // that's why clear the list and fill it in again 00074 //AddMissingItems(items, itemNames); 00075 //RemoveUnmatchedItems(items, itemNames); 00076 items.Clear(); 00077 if (itemNames != null) 00078 { 00079 for (int i = 0; i < itemNames.Length; i++) 00080 { 00081 ListItem item = new ListItem(itemNames[i], itemValues[i]); 00082 items.Add(item); 00083 } 00084 } 00085 00086 UI.Common.PageManagement.InitializeItemsTooltips(items); 00087 } 00088 #endregion 00089 #region Private helper methods 00090 00095 private static void AddMissingItems(ListItemCollection items, string[] itemNames) 00096 { 00097 if (itemNames != null) 00098 { 00099 foreach (string itemName in itemNames) 00100 { 00101 if (items.FindByText(itemName) == null) 00102 { 00103 ListItem item = new ListItem(itemName); 00104 00105 items.Add(item); 00106 } 00107 } 00108 } 00109 } 00115 private static void RemoveUnmatchedItems(ListItemCollection items, string[] itemNames) 00116 { 00117 if (itemNames != null) 00118 { 00119 ListItemCollection itemsToRemove = new ListItemCollection(); 00120 foreach (ListItem item in items) 00121 { 00122 bool found = false; 00123 foreach (string itemName in itemNames) 00124 { 00125 if (itemName == item.Text) 00126 { 00127 found = true; 00128 break; 00129 } 00130 } 00131 if (!found) 00132 itemsToRemove.Add(item); 00133 } 00134 foreach (ListItem item in itemsToRemove) 00135 items.Remove(item); 00136 } 00137 else 00138 items.Clear(); 00139 } 00140 #endregion 00141 } 00142 }